package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.TrainScheduleEntity;
import com.my12306.train.service.TrainScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 发车表(车次表)
 *
 * @author ËÕÄÁÏ¦
 * @email
 * @date 2020-07-24 20:58:07
 */
@RestController
@RequestMapping("/trainSchedule")
public class TrainScheduleController {
    @Autowired
    private TrainScheduleService trainScheduleService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page = trainScheduleService.queryTrainSchedulePage(pageVo);
        return ResponseData.ok().put("page", page);
    }

    @GetMapping("/add/para")
    public ResponseData getParameters(@RequestParam(value = "id",required = false) Long id){
        return  trainScheduleService.getAddParameters(id);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public ResponseData info(@PathVariable("id") Long id) {
        TrainScheduleEntity trainSchedule = trainScheduleService.getById(id);

        return ResponseData.ok().put("trainSchedule", trainSchedule);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public ResponseData save(@RequestBody TrainScheduleEntity trainSchedule) {
        trainScheduleService.saveTrainSchedule(trainSchedule);

        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public ResponseData update(@RequestBody TrainScheduleEntity trainSchedule) {
        trainScheduleService.updateTrainScheduleById(trainSchedule);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public ResponseData delete(@RequestBody List<Long> trainScheduleIds) {
        System.out.println(trainScheduleIds);
        trainScheduleService.deleteTrainScheduleBatchByIds(trainScheduleIds);
        return ResponseData.ok();
    }
}
